package com.jeesite.modules.rc.web;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.rc.entity.RcPerson;
import com.jeesite.modules.rc.service.RcPersonService;

/**
 * 人才表Controller
 * @author ccz
 * @version 2025-03-24
 */
@Controller
@RequestMapping(value = "${adminPath}/rc/rcPerson")
public class RcPersonController extends BaseController {

	@Autowired
	private RcPersonService rcPersonService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public RcPerson get(String rcId, boolean isNewRecord) {
		return rcPersonService.get(rcId, isNewRecord);
	}

	/**
	 * 管理主页
	 */
	@RequiresPermissions("rc:rcPerson:view")
	@RequestMapping(value = "index")
	public String index(RcPerson rcPerson, Model model) {
		model.addAttribute("rcPerson", rcPerson);
		return "modules/rc/rcPersonIndex";
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("rc:rcPerson:view")
	@RequestMapping(value = {"list", ""})
	public String list(RcPerson rcPerson, Model model) {
		model.addAttribute("rcPerson", rcPerson);
		return "modules/rc/rcPersonList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("rc:rcPerson:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<RcPerson> listData(RcPerson rcPerson, HttpServletRequest request, HttpServletResponse response) {
		rcPerson.setPage(new Page<>(request, response));
		Page<RcPerson> page = rcPersonService.findPage(rcPerson);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("rc:rcPerson:view")
	@RequestMapping(value = "form")
	public String form(RcPerson rcPerson, Model model) {
		model.addAttribute("rcPerson", rcPerson);
		return "modules/rc/rcPersonForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("rc:rcPerson:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated RcPerson rcPerson) {
		rcPersonService.save(rcPerson);
		return renderResult(Global.TRUE, text("保存人才表成功！"));
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("rc:rcPerson:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(RcPerson rcPerson) {
		rcPersonService.delete(rcPerson);
		return renderResult(Global.TRUE, text("删除人才表成功！"));
	}







	/**
	 * 查询本身及以下地区的人列表
	 */
	@RequiresPermissions("rc:rcPerson:view")
	@RequestMapping(value = {"personList", ""})
	public String personList(RcPerson rcPerson, Model model) {
		model.addAttribute("rcPerson", rcPerson);
		return "modules/rc/rcPersonDataList";
	}

	/**
	 * 查询本身及以下地区的人列表数据
	 */
	@RequiresPermissions("rc:rcPerson:view")
	@RequestMapping(value = "personData")
	@ResponseBody
	public List<RcPerson> personData(RcPerson rcPerson) {
		List<RcPerson> page = rcPersonService.findPersonData(rcPerson);
		return page;
	}
}